/*
 * WorxResultSet.java
 *
 * Created Apr 29, 2006
 * David Connell
 * Copyright (c) 2005 Synergy Systems, Inc
 */
package org.puresilk.afx.data;

import java.util.*;
import org.puresilk.afx.base.SilkAfxException;

/**
 * A disconnected result set for queries. 
 */
public class SilkAfxResultSet {
	private Vector<SilkAfxRow> rows = null;
	private Iterator itr = null;
	private SilkAfxRow curr = null;
	
	/**
	 *	Wrapper for WorxRow container
	 */
	public SilkAfxResultSet() {
		super();
		rows = new Vector<SilkAfxRow>();
	}

	public void add(SilkAfxRow row) {
		rows.add(row);
	}
	
	public void reset() {
		itr = null;
	}
	
	public boolean next() {
		boolean rv = false;
		
		// check for new run
		if(itr == null){
			itr = rows.iterator();
		}
		
		// check for more results
		if(itr.hasNext()) {
			curr = (SilkAfxRow)itr.next();
			rv = true;
		}
		
		// send back what you find
		return rv;
	}
	
	public int size() {
		return rows.size();
	}
	
	public int getInt(String fld) throws SilkAfxException {
		if(curr == null)
			throw new SilkAfxException("Invalid record.");
		
		return curr.getInt(fld);
	}
	
	public String getString(String fld) throws SilkAfxException {
		if(curr == null)
			throw new SilkAfxException("Invalid record.");
		
		return curr.getString(fld);
	}
	
	public Date getDate(String fld) throws SilkAfxException {
		if(curr == null)
			throw new SilkAfxException("Invalid record.");
		
		return curr.getDate(fld);
	}
	
	public Integer getInteger(String fld) throws SilkAfxException {
		if(curr == null)
			throw new SilkAfxException("Invalid record.");
		
		return curr.getInteger(fld);
	}
	
	public double getDouble(String fld) throws SilkAfxException {
		if(curr == null)
			throw new SilkAfxException("Invalid record.");
		
		return curr.getDouble(fld);
	}

	public Object getObject(String fld) throws SilkAfxException {
		if(curr == null)
			throw new SilkAfxException("Invalid record.");
		
		return curr.getObject(fld);
	}

}
